package cn.dujc.superkid.activities;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import java.util.List;

import cn.dujc.core.ui.BaseActivity;
import cn.dujc.superkid.R;
import cn.dujc.superkid.api.HttpHelper;
import cn.dujc.superkid.api.QMap;
import cn.dujc.superkid.api.Result;
import cn.dujc.superkid.api.ResultCallBack;
import cn.dujc.superkid.bean.CupExamineResult;
import cn.dujc.superkid.bean.CupListResult;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.utils.Preferences;

/**
 * Created by Administrator on 2018/10/23 0023.
 */

public class CupExplainActivity extends BaseActivity {
    String examine_id;
    TextView tv1, tv2;

    @Override
    public int getViewId() {
        return R.layout.activivity_cup_explain;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
        examine_id = getIntent().getStringExtra("examine_id");
        setTitle("杯赛");
        initView();
        loadData();
    }

    private void initView() {
        tv1 = findViewById(R.id.cup_explain_tv);
        tv2 = findViewById(R.id.cup_explain_tv2);
        findViewById(R.id.cup_explain_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mActivity,CupUnitTest.class);
                intent.putExtra("examine_id",examine_id);
                startActivity(intent);
                finish();
            }
        });
    }

    private void loadData() {
        final RegisterResult loginResult = Preferences.getInstance().getLoginResult(this);
        HttpHelper.getCupMatch().cupExamine(QMap.build()
                .put("user_id", loginResult.getUid())
                .put("channel", Preferences.getInstance().getChannel(mActivity).getChannel_id())
                .put("examine_id", examine_id)
                .put("logincode", loginResult.getLogincode())
                .create()).enqueue(new ResultCallBack<Result<CupExamineResult>>(mActivity) {
            @Override
            public void onSuccessCallback(int code, Result<CupExamineResult> body) {
                tv1.setText(Html.fromHtml(body.getData().getEx_desc()));
                tv2.setText("共计" + body.getData().getExamine_num() + "题，" + "考试时间" + body.getData().getEx_usedtime() + "分钟");
            }
        });
    }
}
